using System;
using System.Collections.Generic;
using Dict.DataModel;

namespace Dict.Dao
{
    public class TableNPCDao:DaoBase<TableNPC>
    {
        public override void AddPrimaryIndex(TableNPC model)
        {
            cachePrimary[model.npcId.ToString()] = model;
        }

        public override string GetFileName()
        {
            return "TableNPC.txt";
        }

        protected override TableNPC ParseRowData(string[] rowData)
        {
            TableNPC data = new TableNPC();
			data.npcId = rowData [0];
			data.sceneName = rowData [1];

            if (string.IsNullOrEmpty(rowData[2]))
            {
                data.type = 0;
            }
            else
            {
                data.type = int.Parse(rowData[2]);
            }
			data.heroId = rowData [3];
			data.weaponId = rowData [4];

            if (string.IsNullOrEmpty(rowData[5]))
            {
                data.bornX = 0;
            }
            else
            {
                data.bornX = double.Parse(rowData[5]);
            }

            if (string.IsNullOrEmpty(rowData[6]))
            {
                data.bornY = 0;
            }
            else
            {
                data.bornY = double.Parse(rowData[6]);
            }

            if (string.IsNullOrEmpty(rowData[7]))
            {
                data.bornZ = 0;
            }
            else
            {
                data.bornZ = double.Parse(rowData[7]);
            }

            if (string.IsNullOrEmpty(rowData[8]))
            {
                data.bornAngle = 0;
            }
            else
            {
                data.bornAngle = double.Parse(rowData[8]);
            }
			data.nameId = rowData [9];
			data.animName = rowData [10];
			data.pageName = rowData [11];
			data.pageOption = rowData [12];

            if (string.IsNullOrEmpty(rowData[13]))
            {
                data.pageLevel = 0;
            }
            else
            {
                data.pageLevel = int.Parse(rowData[13]);
            }
			data.bubbleText = rowData [14];
			data.miniMapIcon = rowData [15];

            if (string.IsNullOrEmpty(rowData[16]))
            {
                data.canTransfer = 0;
            }
            else
            {
                data.canTransfer = int.Parse(rowData[16]);
            }

            if (string.IsNullOrEmpty(rowData[17]))
            {
                data.transferX = 0;
            }
            else
            {
                data.transferX = double.Parse(rowData[17]);
            }

            if (string.IsNullOrEmpty(rowData[18]))
            {
                data.transferY = 0;
            }
            else
            {
                data.transferY = double.Parse(rowData[18]);
            }

            if (string.IsNullOrEmpty(rowData[19]))
            {
                data.transferZ = 0;
            }
            else
            {
                data.transferZ = double.Parse(rowData[19]);
            }

            if (string.IsNullOrEmpty(rowData[20]))
            {
                data.transferAngle = 0;
            }
            else
            {
                data.transferAngle = double.Parse(rowData[20]);
            }

            if (string.IsNullOrEmpty(rowData[21]))
            {
                data.necessary = 0;
            }
            else
            {
                data.necessary = int.Parse(rowData[21]);
            }
			data.bigMapIcon = rowData [22];
			data.npcDes = rowData [23];

            return data;
        }


        public override void AddOneIndex(TableNPC model)
        {
            if (!cacheOneIndex.ContainsKey(model.sceneName.ToString()))
            {
                cacheOneIndex[model.sceneName.ToString()] = new List<TableNPC>();
            }
            cacheOneIndex[model.sceneName.ToString()].Add(model);
        }
    

    }

}
